package com.gszyxy.bigdataclass1group3.plateform.handler;


import com.gszyxy.bigdataclass1group3.plateform.service.PlateformService;

import com.gszyxy.bigdataclass1group3.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("plateform")
public class PlateformHandler {

    @Resource
    private PlateformService plateformService;

    @GetMapping("list")
    public R list(){
        return  plateformService.list().size() > 0 ? R.ok(plateformService.list()) :R.fail("暂时无商家入驻");

    }

    @PostMapping("access")
    public R access(@RequestParam("mid") Integer mid, HttpServletRequest request){

        String loginUser = (String) request.getSession().getAttribute("mname");

        if(!loginUser.equals("admin")){
            return R.fail("您不是管理员,没有审核权限");
        }
        return plateformService.updateMerchant(mid) == 1 ? R.ok("审核成功") : R.fail("审核失败");
    }

}
